package org.jeecg.jxc.customer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.jxc.customer.entity.Customer;
import org.jeecg.jxc.customer.entity.RequestCustomer;
import org.jeecg.jxc.customer.service.impl.CustomerServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @PackageName: org.jeecg.jxc.customer.controller
 * @ClassName: CustomerController
 * @author: zgq
 * @date: 2022/6/21 19:09
 * @Description: 客户管理接口
 **/

@RestController
@RequestMapping("/customer")
@Slf4j
public class CustomerController {

    @Resource
    private CustomerServiceImpl customerService;

    //查询客户列表
    @PostMapping("/list")
    public ResponseEntity<IPage<Customer>> list(@RequestBody RequestCustomer requestCustomer){
        Page<Customer> page = new Page<>(Integer.valueOf(requestCustomer.getPage()),Integer.valueOf(requestCustomer.getRows()));
        IPage<Customer> customerPage = customerService.pageList(page,requestCustomer.getCustomerName());
        return ResponseEntity.ok(customerPage);
    }
    //添加和修改
    @PostMapping("/save")
    public ResponseEntity<?> save(@RequestParam(value = "customerId",required = false) Integer customerId,@RequestBody Customer customer){
        return ResponseEntity.ok(customerService.save(customerId,customer));
    }

    //删除
    @PostMapping("/delete")
    public ResponseEntity<?> deleteByIds(@RequestBody RequestCustomer requestCustomer){
        return ResponseEntity.ok(customerService.deleteByIds(requestCustomer.getIds()));
    }
}
